#ifndef CLIENT_H
#define CLIENT_H

#include "header.h"
#include "logger.h"
#include "config.h"

#define SERVER_IP "127.0.0.1"
#define SERVER_PORT 1234
#define MAX_USERNAME_LEN 32
#define MAX_PASSWORD_LEN 32
#define MAX_COMMAND_LEN 1024
#define MAX_ARGS 10

#define PATH_MAX 4096  // 如果系统没有定义 PATH_MAX，我们自己定义一个合理的值

// 定义消息类型
#define MSG_TYPE_LOGIN 1
#define MSG_TYPE_LOGOUT 2
#define MSG_TYPE_DATA 3
#define MSG_TYPE_REGISTER 4
#define MSG_TYPE_REGISTER_SUCCESS 5
#define MSG_TYPE_REGISTER_FAIL 6
#define MSG_TYPE_LOGIN_SUCCESS 7
#define MSG_TYPE_LOGIN_FAIL 8

// 新增文件操作相关的消息类型
#define MSG_TYPE_CD 9
#define MSG_TYPE_LS 10
#define MSG_TYPE_PUTS 11
#define MSG_TYPE_GETS 12
#define MSG_TYPE_RM 13
#define MSG_TYPE_PWD 14
#define MSG_TYPE_MKDIR 15

// 操作结果消息类型
#define MSG_TYPE_SUCCESS 16
#define MSG_TYPE_FAIL 17

typedef struct {
    int socket;
    char username[MAX_USERNAME_LEN];
    bool is_logged_in;
    char current_dir[PATH_MAX];  // 新增字段，存储当前会话中客户所在的目录
} ClientInfo;

typedef struct {
    int type;
    int length;
    char data[1024];
} Message;

// 函数声明
int create_client_socket();
void connect_to_server(int sock);
void handle_client_logic(ClientInfo* client);
int send_message(int socket, Message *msg);
int receive_message(int socket, Message *msg);
int register_user(ClientInfo* client);
int login_user(ClientInfo* client);
void process_command(ClientInfo* client, char* command);

// 命令处理函数声明
void handle_cd(ClientInfo* client, int argc, char* argv[]);
void handle_ls(ClientInfo* client, int argc, char* argv[]);
void handle_puts(ClientInfo* client, int argc, char* argv[]);
void handle_gets(ClientInfo* client, int argc, char* argv[]);
void handle_rm(ClientInfo* client, int argc, char* argv[]);
void handle_pwd(ClientInfo* client, int argc, char* argv[]);
void handle_mkdir(ClientInfo* client, int argc, char* argv[]);

#endif
